/**
 * DbHandle.java
 * Copyright (C) 2011 Yuanyan<yuanyan.cao@gmail.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * For information on how to redistribute this software under
 * the terms of a license other than GNU General Public License
 * contact yuanyan.cao@gmail.com
 */
package edu.rabbit.kernel.db;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;


import edu.rabbit.kernel.IBackend;
import edu.rabbit.kernel.IConfig;
import edu.rabbit.kernel.IDbHandle;
import edu.rabbit.kernel.DbFlags;
import edu.rabbit.kernel.DbUtility;
import edu.rabbit.kernel.fs.DbFileSystemsManager;
import edu.rabbit.kernel.fs.IFileSystem;
import edu.rabbit.kernel.mutex.EmptyMutex;
import edu.rabbit.kernel.mutex.Mutex;
import edu.rabbit.kernel.mutex.IMutex;
import edu.rabbit.table.IBusyHandler;
import edu.rabbit.table.IOptions;

/**
 * @author Yuanyan<yanyan.cao@gmail.com>
 * 
 * 
 */
public class DbHandle implements IDbHandle {

    private Set<DbFlags> flags = DbUtility.noneOf(DbFlags.class);
    private IConfig config = new DbConfig();
    private IFileSystem fileSystem = DbFileSystemsManager.getManager().find(null);
    private IMutex iMutex = new EmptyMutex();
    private List<IBackend> backends = new LinkedList<IBackend>();
    private IOptions iOptions;
    private IBusyHandler iBusyHandler;

    public DbHandle() {
        if (config.isSynchronizedThreading()) {
            iMutex = new Mutex();
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getBackends()
     */
    public List<IBackend> getBackends() {
        return backends;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getBusyHaldler()
     */
    public IBusyHandler getBusyHandler() {
        return iBusyHandler;
    }

    /**
     * @param iBusyHandler
     *            the busyHandler to set
     */
    public void setBusyHandler(IBusyHandler iBusyHandler) {
        this.iBusyHandler = iBusyHandler;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getConfig()
     */
    public IConfig getConfig() {
        return config;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getFileSystem()
     */
    public IFileSystem getFileSystem() {
        return fileSystem;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getFlags()
     */
    public Set<DbFlags> getFlags() {
        // TODO Auto-generated method stub
        return flags;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getMutex()
     */
    public IMutex getMutex() {
        return iMutex;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.tmatesoft.rabbit.core.IDb#getSavepointNum()
     */
    public int getSavepointNum() {
        // TODO Auto-generated method stub
        return 0;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.tmatesoft.rabbit.core.IDb#setConfig(org.tmatesoft.rabbit.core
     * .IConfig)
     */
    public void setConfig(IConfig config) {
        // TODO Auto-generated method stub

    }

    public IOptions getOptions() {
        return iOptions;
    }

    public void setOptions(IOptions iOptions) {
        this.iOptions = iOptions;
    }
}
